/*
 *  Copyright 2019-2020 Zheng Jie
 *
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *  http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 */
package me.zhengjie.modules.biz.domain;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.bean.copier.CopyOptions;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.hibernate.annotations.CreationTimestamp;
import org.hibernate.annotations.UpdateTimestamp;

import javax.persistence.*;
import javax.validation.constraints.NotNull;
import java.io.Serializable;
import java.sql.Timestamp;
import java.util.List;

/**
 * @author Admin
 * @website https://eladmin.vip
 * @description /
 * @date 2023-03-13
 **/
@Entity
@Data
@Table(name = "hj_storehouse_order")
public class StorehouseOrder implements Serializable {

    public static final int STATUS_YI_LING_QU = 5;//已领取，待归还
    public static final int STATUS_RETURNED = 8;//已归还

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "`id`")
    @ApiModelProperty(value = "id")
    private Integer id;

    @Column(name = "`no`")
    @ApiModelProperty(value = "订单号")
    private String no;

    @Column(name = "`status`")//0 刚创建待审批；2审核通过待领取；3 审核未通过；4取消；5已领取；待归还；6已归还
    @ApiModelProperty(value = "状态")
    private Integer status;

    @Column(name = "`user_id`", nullable = false)
    @NotNull
    @ApiModelProperty(value = "申请人ID")
    private Integer userId;

    @Column(name = "`storehouse_admin_id`")
    @ApiModelProperty(value = "仓库管理员ID")
    private Integer storehouseAdminId;

    @Column(name = "`storehouse_admin_note`")
    @ApiModelProperty(value = "storehouseAdminNote")
    private String storehouseAdminNote;

    @Column(name = "`director_id`")
    @ApiModelProperty(value = "主任ID")
    private Integer directorId;

    @Column(name = "`director_note`")
    @ApiModelProperty(value = "directorNote")
    private String directorNote;

    @Column(name = "`note`")
    @ApiModelProperty(value = "note")
    private String note;

    @Column(name = "`data`")
    @ApiModelProperty(value = "data")
    private String data;

    @Column(name = "`created_at`")
    @CreationTimestamp
    @ApiModelProperty(value = "createdAt")
    private Timestamp createdAt;

    @Column(name = "`updated_at`")
    @UpdateTimestamp
    @ApiModelProperty(value = "updatedAt")
    private Timestamp updatedAt;

    //订单详情信息
    @Transient
    private List<StorehouseOrderDetail> details;

    public void copy(StorehouseOrder source) {
        BeanUtil.copyProperties(source, this, CopyOptions.create().setIgnoreNullValue(true));
    }
}
